/* eslint-disable regexp/no-unused-capturing-group */
export interface RuleOptionType {
  label: string
  value: string
  message: string
  required?: boolean
  // 验证条件
  validateCondition?: (value: string) => Promise<boolean> | boolean

}

// 验证规则可选项
export const ruleTypeOptions: RuleOptionType[] = [
  {
    label: '必填',
    value: '必填',
    message: '请输入',
    required: true,
  },
  {
    label: '手机号',
    value: '手机号',
    message: '请输入正确的手机号',
    validateCondition: (value: string) => {
      return new Promise((resolve) => {
        resolve(/^1[3-9]\d{9}$/.test(value))
      })
    },
  },
  {
    label: '邮箱',
    value: '邮箱',
    message: '请输入正确的邮箱',
    validateCondition: (value: string) => {
      return new Promise((resolve) => {
        resolve(/^[\w.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z0-9]{2,6}$/i.test(value))
      })
    },
  },
  {
    label: '数字',
    value: '数字',
    message: '请输入数字',
    validateCondition: (value: string) => {
      return new Promise((resolve) => {
        resolve(/^\d+$/.test(value))
      })
    },
  },
  {
    label: '字母',
    value: '字母',
    message: '请输入字母',
    validateCondition: (value: string) => {
      return new Promise((resolve) => {
        resolve(/^[a-z]+$/i.test(value))
      })
    },
  },
]
